//app.js
App({
    onLaunch: function (res) {
        console.log(res);
        // app.js /index.js
        let inviterId = null
        let productId = null
        // 扫描小程序二维码进入
        if(res.scene === 1047 ){
            if (res.query.scene.indexOf('&') !== -1) {
                let query = res.query.scene
                productId = query.split('&')[0];
                inviterId = query.split("&")[1];
            }
        } else {
            if (res.query.course_id) {
                productId = res.query.course_id
                inviterId = res.query.inviter_id
            }
        }

        if (!wx.cloud) {
            console.error('请使用 2.2.3 或以上的基础库以使用云能力')
        } else {
            wx.cloud.init({
                env: 'minapp-9b93b2',
                traceUser: true,
            })
        }
        let openid = wx.getStorageSync('openid') || null
        let unionid = wx.getStorageSync('unionid') || null
        let userInfo = wx.getStorageSync('userInfo') || null
        let userId = wx.getStorageSync('user_id') || null
        let isBinded = wx.getStorageSync('is_mobile_binded') || null
        let user = wx.getStorageSync('user') || null
        this.globalData = {
            user: user,
            isBinded: isBinded,
            inviterId: inviterId,
            productId: productId,
            userId: userId,
            userInfo: userInfo,
            openid: openid,
            unionid: unionid,
            ccsdk: requirePlugin('ccsdk')
        }
    },
})
